import {Toast} from "vant";

import 'vant/lib/toast/index.css'
export declare type ToastType = 'loading' | 'success' | 'fail';
export declare type ToastPosition = 'top' | 'middle' | 'bottom';

declare type messageType = string | number

// interface Rules {
//     [key:String]:()=>{}
// }

declare type toastSetting = {
    type?:ToastType;
    duration?:number;
    icon?:string;
    message?: string | number;
    position?:ToastPosition;
    forbidClick?:boolean;
    overlay?:boolean;
}


export default function useToast(){
    return function (options:toastSetting = {duration:2000,forbidClick:true,overlay:false}){
        if (typeof options !== 'object'){
            return Toast(options)
        }
        const {type} = options
        if(!type){
            return Toast(options)
        }else {
            return Toast[type](options)
        }
    }
}
